<?php
use wepay\join\demo\common\SignUtil;
use wepay\join\demo\common\DesUtils;
use wepay\join\demo\common\ConfigUtil;
use wepay\join\demo\api\WebAsynNotificationCtrl;
use wepay\join\demo\api\WebBase;
use wepay\join\demo\api\WebSecurity;
class ApiController extends BaseController
{

    /**
     * 参数验证
     * @param $obj
     * @param $arr
     * @author lzhp
     * @date 2016-09-03
     * @return bool
     */
    public function  checkProperties($obj, $arr)
    {
        if(empty($arr)) return true;
        $obj    =   (array) $obj;

        foreach($arr as $v){
            if(empty($obj[$v])){
                return false;}
        }
        return true;
    }

    /**
     * 获取App信息
     * @author  lzhp
     * @date 2016-09-09
     */
    public function IndexApp()
    {
        try{
            $data = ApiService::instance()->GetIndexApp();
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS,"获取APP信息成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 用户登录
     * @author lzhp
     * @data 2016-09-03
     */
    public function DeposeLogin()
    {
        #收集信息
        $paramObj                   =          new stdClass();
        $paramObj->mobile           =          $this->getParam('mobile');
        $paramObj->password         =          $this->getParam('password');


        #逻辑处理
        try{
            $data = ApiService::instance()->DeposeLogin($paramObj);
            return Response::json([
                'code' => ErrorCodeEnum::STATUS_SUCCESS,
                'msg'  => '登录成功!',
                'data' => $data
            ]);
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 注销登录
     * @return mixed
     * @author lzhp
     * @data 2016-09-03
     */
    public function Logout()
    {
        #逻辑处理
        try{
            $data = ApiService::instance()->Logout();
            return Response::json([
                'code' => ErrorCodeEnum::STATUS_SUCCESS,
                'msg'  => '注销成功!',
                'data' => $data
            ]);
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 用户注册
     * @author lzhp
     * @data 2016-09-03
     */
    public function DeposeRegister()
    {

        #接收参数
        $paramObj                       =          new stdClass();
        $paramObj->mobile               =          $this->getParam('mobile');               //手机号
        $paramObj->password             =          $this->getParam('password');             //密码

        #逻辑处理
        try{
            $data = ApiService::instance()->DeposeRegister($paramObj);
            return Response::json([
                'code' => ErrorCodeEnum::STATUS_SUCCESS,
                'msg'  => '注册成功!',
                'data' => $data
            ]);
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }


    /**
     * 忘记密码
     * @author lzhp
     * @data  2016-09-03
     */
    public function ForgetPassword()
    {
        #收集信息
        $paramObj                          =          new stdClass();
        $paramObj->mobile                  =          $this->getParam('mobile');
        $paramObj->password                =          $this->getParam('password');

        #逻辑处理
        try{
            $data = ApiService::instance()->ForgetPassword($paramObj);
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS, "密码修改成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }

    }


    /**
     * 获取首页数据
     * @author lzhp
     * @data  2016-09-05
     */
    public function IndexData()
    {
        $page = $this->getParam('page');
        #收集信息
        $paramObj                          =          new stdClass();
        $paramObj->page                    =          empty($page)?1:$page;

        #逻辑处理
        try{
            $BannerData = ApiService::instance()->BannerData();
            $IndexData = ApiService::instance()->IndexData($paramObj);
            $arr=array(
                'Bannerdata' =>$BannerData ,
                'IndexData' =>$IndexData ,
            );
           $this->rest->success($arr, ErrorCodeEnum::STATUS_SUCCESS,"获取首页数据成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }


    /**
     * 商城数据搜索
     * @author lzhp
     * @data  2016-09-05
     */
    public function ShopData()
    {
        $page = $this->getParam('page');
        #收集信息
        $paramObj                          =          new stdClass();
        $paramObj->page                    =          empty($page)?1:$page;
        $paramObj->product_id              =           $this->getParam('product_id');
        $paramObj->city                    =           $this->getParam('city');
        $paramObj->category                =           $this->getParam('category');
        $paramObj->factory                 =           $this->getParam('factory');
        $paramObj->keywords                =           $this->getParam('keywords');
        $paramObj->spec                    =           $this->getParam('spec');


        #逻辑处理
        try{
            $data = ApiService::instance()->ShopData($paramObj);
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS,"获取商城数据成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 钢厂列表
     * @author lzhp
     * @data  2016-09-08
     */
    public function FactoryList()
    {
        #逻辑处理
        try{
            $data = ApiService::instance()->FactoryList();
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS,"获取钢厂列表成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 行情快讯
     * @author lzhp
     * @data  2016-09-05
     */
    public function MarketInformation()
    {
        $page = $this->getParam('page');
        #收集信息
        $paramObj                          =          new stdClass();
        $paramObj->page                    =          empty($page)?1:$page;

        #逻辑处理
        try{
            $data = ApiService::instance()->MarketInformation($paramObj);
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS,"获取资讯数据成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 行情资讯页面
     * @return mixed
     * @author lzhp
     * @data  2016-09-07
     */
    public function InformationShow()
    {
        #收集信息
        $paramObj                        =          new stdClass();
        $paramObj->id                    =          $this->getParam('id');

        #逻辑处理
        $data = ApiService::instance()->InformationShow($paramObj);
        return $this->view('shop.api_information_details')->with('data',$data);
    }

    /**
     * 发布求购单
     * @author lzhp
     * @data  2016-09-06
     */
    public function RequestList()
    {
        #收集信息
        $paramObj                          =          new stdClass();
        $paramObj->category                =          $this->getParam('category');
        $paramObj->city                    =          $this->getParam('city');
        $paramObj->description             =          $this->getParam('description');

        #逻辑处理
        try{
            $data = ApiService::instance()->RequestList($paramObj);
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS,"发布求购单成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 品类信息
     * @author lzhp
     * @data  2016-09-06
     */
    public function CategoryData()
    {
        #逻辑处理
        try{
            $data = ApiService::instance()->CategoryData();
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS,"获取品类信息成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 企业认证
     *  @author lzhp
     * @data  2016-09-07
     */
    public function CompanyAuth()
    {
        #收集信息
        $paramObj                          =          new stdClass();
        $paramObj->company                 =          $this->getParam('company');
        $paramObj->address                 =          $this->getParam('address');
        $paramObj->owner                   =          $this->getParam('owner');
        $paramObj->phone                   =          $this->getParam('phone');
        $paramObj->operate_license         =          $this->getParam('operate_license');
        $paramObj->organization            =          $this->getParam('organization');
        $paramObj->tax_license             =          $this->getParam('tax_license');
        $paramObj->account_licence         =          $this->getParam('account_licence');

        #逻辑处理
        try{
            $data = ApiService::instance()->CompanyAuth($paramObj);
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS,"企业认证审核!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }

    }

    /**
     * 修改登录密码
     * @author lzhp
     * @data  2016-09-08
     */
    public function UploginPwd()
    {
        #收集信息
        $paramObj                          =          new stdClass();
        $paramObj->old_pwd                 =          $this->getParam('old_pwd');
        $paramObj->new_pwd                 =          $this->getParam('new_pwd');

        #逻辑处理
        try{
            $data = ApiService::instance()->UploginPwd($paramObj);
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS, "修改登录密码成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 消息列表
     * @author lzhp
     * @data  2016-09-08
     */
    public function MessageList()
    {
        $page = $this->getParam('page');
        #收集信息
        $paramObj                          =          new stdClass();
        $paramObj->page                    =          empty($page)?1:$page;
        $paramObj->status                  =          $this->getParam('status');

        #逻辑处理
        try{
            $data = ApiService::instance()->MessageList($paramObj);
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS, "获取消息列表成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 最新消息
     * @author lzhp
     * @data  2016-09-09
     */
    public function NewMessage()
    {


        #逻辑处理
        try{
            $data = ApiService::instance()->NewMessage();
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS, "获取最新消息成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }

    }

    /**
     * 城市列表
     * @author lzhp
     * @data  2016-09-09
     */
    public function CityList()
    {
        #逻辑处理
        try{
            $data= ApiService::instance()->CityList();
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS, "获取城市列表成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }


    /**
     * 获取上传图片token
     *  @author lzhp
     *  @data  2016-09-10
     */
    public function GetToken()
    {
        #逻辑处理
        try{
            $data['token'] =   QiniuUpload::instance()->generateToken();
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS, "获取token成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }

    }


    /**
     *获取个人信息
     *  @author lzhp
     *  @data  2016-09-10
     */
    public function GetUserInformation()
    {
        #逻辑处理
        try{
            $data= ApiService::instance()->GetUserInformation();
            return Response::json([
                'code' => ErrorCodeEnum::STATUS_SUCCESS,
                'msg'  => '获取个人信息!',
                'data' => $data
            ]);
            //$this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS, "!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }

    }

    /**
     * 热门搜索
     * @author lzhp
     *  @data  2016-09-13
     */
    public function HotSearch()
    {
        #逻辑处理
        try{
            $data= ApiService::instance()->HotSearch();
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS, "获取热门搜索!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 用户协议
     * @return mixed
     * @author lzhp
     * @data  2016-09-13
     */
    public function UserRule()
    {
        //$data =  ApiService::instance()->UserRule();
        return $this->view('webview.glw_sample');
    }


    /**
     * 修改头像
     * @author lzhp
     * @data  2016-09-14
     */
    public function UpAvatar()
    {
        #收集信息
        $paramObj                          =          new stdClass();
        $paramObj->avatar                  =          $this->getParam('avatar');

        #逻辑处理
        try{
            $data = ApiService::instance()->UpAvatar($paramObj);
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS, "修改头像成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 自动登录
     */
    public function AutoLogin()
    {
        #收集信息
        $paramObj                   =          new stdClass();
        $paramObj->user_id          =          $this->getParam('user_id');

        #逻辑处理
        try{
            $data = ApiService::instance()->AutoLogin($paramObj);
            $this->rest->success($data, ErrorCodeEnum::STATUS_SUCCESS, "自动登录!");

        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }

    }



    /**
     * app购物车信息列表
     * @author xf
     * @data  2016-09-05
     */
    public function  CartInfo(){
        #逻辑处理
        try{
            $cartdata = ApiService::instance()->Appcartlist();
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"获取购物车数据成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * app删除购物车
     * @author xf
     * @data  2016-09-05
     */
    public function  DeleteCart(){
        #接收参数
        $cart_id = $this->getParam('cart_id');
        $paramObj                   =   new stdClass();
        $paramObj->cart_id             =  $cart_id;
        try{
            $cartdata = ApiService::instance()->DeleteCarte($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"成功删除商品!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }

    }

    /**
     * app更新购物车
     * @author xf
     * @data  2016-09-05
     */
    public function  UpdateCart(){
        #接收参数
        $useable_stock                  = $this->getParam('useable_stock');
        $cart_id                        = $this->getParam('cart_id');
        $paramObj                       = new stdClass();
        $paramObj->useable_stock        = $useable_stock;
        $paramObj->cart_id              = $cart_id;
        try{
            $cartdata = ApiService::instance()->UpdateCarte($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"获取购物车数据成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }

    }

    /**
     * app编辑购物车详情页面
     * @author xf
     * @data  2016-09-05
     */
    public function  UpdateCartone(){
        $cart_id                        = $this->getParam('cart_id');
        $paramObj                       = new stdClass();
        $paramObj->cart_id              = $cart_id;
        try{
            $cartdata = ApiService::instance()->UpdateCarteone($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"获取购物车详情页成功!");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * app添加购物车
     * @author xf
     * @data  2016-09-05
     */
    public  function AddCart(){
        $product_id                     = $this->getParam('product_id');
        $paramObj                       = new stdClass();
        $paramObj->product_id           = $product_id;
        $paramObj->num                  = $this->getParam('num');
        try{
            if(empty($paramObj->num)){
                $cartdata = ApiService::instance()->AddCarte($paramObj);
                return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"添加购物车成功！");
            }else{
                $cartdata = ApiService::instance()->AddCarte($paramObj);
                return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"购物车数量数据成功！");
            }
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }


    }

    /**
     * APP意见反馈
     * @author xf
     * @data  2016-09-05
     */
    public  function FeedBack(){
        $content                        = $this->getParam('content');
        $mobile                         = $this->getParam('mobile');
        $paramObj                       = new stdClass();
        $paramObj->content              = $content;
        $paramObj->mobile               = $mobile;
        try{
            $cartdata = ApiService::instance()->FeedBack($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"提交成功，感谢您的参与");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }


    /**
     * 确认订单信息
     * @author xf
     * @data  2016-09-07
     */
    public function OrderInfo(){
        $paramObj                      = new stdClass();
        $paramObj->cart_id             =$this->getParam('cart_id');  //选中的ID array(679,797);//
        try{
            $cartdata = ApiService::instance()->OrderInfo($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"确认订单数据成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }


    /**
     *购物车全选清楚
     * @param $paramObj
     * @author xf
     * @date 2016-9-07
     * @return mixed
     * @throws Exception
     */
    public  function CheckdeCart(){
        $paramObj                      = new stdClass();
        $paramObj->cart_id              =$this->getParam('cart_id'); //购物车idarray(811,812);//
        try{
            $cartdata = ApiService::instance()->CheckdeCart($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"全选删除成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     * 添加订单
     * @author xf
     * @data  2016-09-07
     */
    public function AddOrder(){
        $paramObj                       = new stdClass();
        $paramObj->cart_id              =$this->getParam('cart_id'); //array(835,836);//
        $paramObj->pid                  =$this->getParam('pid');     //支付方式

        try{
            $cartdata = ApiService::instance()->AddOrder($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"添加订单成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }


    /**
     *订单列表页
     * @param $paramObj
     * @author xf
     * @date 2016-9-08
     * @return mixed
     * @throws Exception
     */
    public  function APPOrderList(){
        #接收参数
        $paramObj                   =   new stdClass();
        $paramObj->status           =   $this->getParam('status'); //购物车idarray(811,812);
        try{
            $cartdata = ApiService::instance()->APPOrderList($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"订单列表数据成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }


    }

    /**
     *支付方式
     * @param $paramObj
     * @author xf
     * @date 2016-9-08
     * @return mixed
     * @throws Exception
     */
    public  function Payment(){
        try{
            $cartdata = ApiPaymentEnum::$payment;
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"支付方式数据成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }



    }
    /**
     *删除订单
     * @param $paramObj
     * @author xf
     * @date 2016-9-08
     * @return mixed
     * @throws Exception
     */
    public  function APPDelOrder(){
        #接收参数
        $paramObj                   =   new stdClass();
        $paramObj->order_id         =   $this->getParam('order_id');

        try{
            $cartdata = ApiService::instance()->APPDelOrder($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"删除订单成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }

    }

    /**
     *订单详情
     * @param $paramObj
     * @author xf
     * @date 2016-9-09
     * @return mixed
     * @throws Exception
     */
    public  function APPOrderDetail(){
        #接收参数
        $paramObj                   =   new stdClass();
        $paramObj->order_id         =   $this->getParam('order_id');

        try{
            $cartdata = ApiService::instance()->APPOrderDetail($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"订单详情数据成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }
    /**
     *审核后取消订单
     * @param $paramObj
     * @author xf
     * @date 2016-9-08
     * @return mixed
     * @throws Exception
     */
    public  function APPCanceOrder(){
        #接收参数
        $paramObj                   =   new stdClass();
        $paramObj->order_id         =   $this->getParam('order_id');
        try{
            $cartdata = ApiService::instance()->APPCanceOrder($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"取消订单成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     *未审核取消订单
     * @param $paramObj
     * @author xf
     * @date 2016-9-08
     * @return mixed
     * @throws Exception
     */
    public  function APPNotdted(){
        #接收参数
        $paramObj                   =   new stdClass();
        $paramObj->order_id         =   $this->getParam('order_id');
        try{
            $cartdata = ApiService::instance()->APPNotdted($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"取消订单成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     *确认提货
     * @param $paramObj
     * @author xf
     * @date 2016-9-08
     * @return mixed
     * @throws Exception
     */
    public  function APPConfOrder(){
        #接收参数
        $paramObj                   =   new stdClass();
        $paramObj->order_id         =   $this->getParam('order_id');

        try{
            $cartdata = ApiService::instance()->APPConfOrder($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"确认提货成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     *添加开票
     * @param $paramObj
     * @author xf
     * @date 2016-9-08
     * @return mixed
     * @throws Exception
     */
    public  function AddInvoice(){
        #接收参数
        $paramObj                   =   new stdClass();
        $paramObj->order_id         =   $this->getParam('order_id'); //订单号
        $paramObj->company          =   $this->getParam('company'); //公司名称
        $paramObj->address          =   $this->getParam('address'); //邮件地址
        $paramObj->username         =   $this->getParam('username'); //联系人
        $paramObj->phone            =   $this->getParam('phone'); //联系电话
        try{
            $cartdata = ApiService::instance()->AddInvoice($paramObj);
            return     $this->rest->success( $cartdata, ErrorCodeEnum::STATUS_SUCCESS,"发票信息添加成功");
        }catch(Exception $e){
            $this->rest->error($e->getMessage(), $e->getCode(),new stdClass());
        }
    }

    /**
     *订单号传入查询
     */
    public function PayFirst()
    {

        $order_id=$_GET['order_id'];
        if(empty($order_id)){
            return '订单不能为空';
        }
        $data = ApiService::instance()->APPSelectOrder($order_id);
        //return $data;
        return $this->view('webview.pay_first')->with('data',$data);
    }

    /**
     *京东支付
     * @param $paramObj
     * @author xf
     * @date 2016-9-08
     * @return mixed
     * @throws Exception
     */
    public function JdPay()
    {
        $config = Config::get("jd_pay");
        $successCallbackUrl = $config["successCallbackUrl"];
        $failCallbackUrl = $config["failCallbackUrl"];
        $merchantNum = $config["merchantNum"];
        $notifyUrl = 'http://api.ganglianw.com/Api/notify_web';
        //      $amount=$_GET['amount'];
        //      $trade_num=$_GET['trade_num'];
        //      $order_time=$_GET['order_time'];
        $param                          =       [];
        $param['currency']              =      "CNY";//货币类型
        $param['merchantNum']           =       $merchantNum;//商户号
        $param['merchantRemark']        =       "钢链网 —— 钢材全产业链服务平台";//商户备注信息
        $param['failCallbackUrl']       =      $failCallbackUrl;//失败跳转地址
        $param['notifyUrl']             =      $notifyUrl;
        $param['successCallbackUrl']    =      $successCallbackUrl;
        $param['tradeAmount']           =      $_GET['amount']*100;//$_SESSION['array']['amount']*100;//订单金额
        //$param['tradeAmount']           =   1;//订单金额
        $param['tradeDescription']      =       "交易描述";//订单描述
        $param['tradeName']             =       "交易名称";//订单标题
        $param['tradeNum']              =       $_GET['trade_num'];//$_SESSION['array']['trade_num'];//交易流水号
        $param['tradeTime']             =       date('Y-m-d H:i:s',$_GET['order_time']); //订单时间
        //return  $param;
        $param['version']               =       "3.0";
        $param['token']                 =       "";
        $specialJson = array();
        $specialJson["specBankCardNo"]  =  $_GET['specBankCardNo'];
//        $specialJson["specIdCard"]      = $_GET['specIdCard'];
//        $specialJson["specName"]        =  $_GET['specName'];
        $param["specifyInfoJson"]       = json_encode($specialJson);

        $sign = SignUtil::sign($param);
        $param["merchantSign"] = $sign;
        //敏感信息加密
        $_SESSION['tradeAmount'] = $param["tradeAmount"];
        $_SESSION['tradeName'] = $param["tradeName"];
        //获取商户 DESkey
        //对敏感信息进行 DES加密
        $desUtils  = new DesUtils();
//      $config = Config::get("jd_pay");
        $key = $config["desKey"];
        $param["merchantRemark"]    =   $desUtils->encrypt($param["merchantRemark"],$key);
        $param["tradeNum"]          =   $desUtils->encrypt($param["tradeNum"],$key);
        $param["tradeName"]         =   $desUtils->encrypt($param["tradeName"],$key);
        $param["tradeDescription"]  =   $desUtils->encrypt($param["tradeDescription"],$key);
        $param["tradeTime"]         =   $desUtils->encrypt($param["tradeTime"],$key);
        $param["tradeAmount"]       =   $desUtils->encrypt($param["tradeAmount"],$key);
        $param["currency"]          =   $desUtils->encrypt($param["currency"],$key);
        $param["notifyUrl"]         =   $desUtils->encrypt($param["notifyUrl"],$key);
        $param["successCallbackUrl"] =  $desUtils->encrypt($param["successCallbackUrl"],$key);
        $param["failCallbackUrl"]    =  $desUtils->encrypt($param["failCallbackUrl"],$key);
        $param["specifyInfoJson"]    =  $desUtils->encrypt($param["specifyInfoJson"],$key);
        $_SESSION['tradeInfo'] = $param;

        //return $param;

        return $this->view('webview.pay_submit_test');
    }

    public function Notify(){
        $MD5_KEY="zQmMsDHKkJnbfpwaoyjqmdqrsbOrMloB";
        $DES_KEY="nZFFhbWP8ftPhrUNlyAT0MLsW9/0iR/j";
        $w = new WebAsynNotificationCtrl();
        $date = $w->execute ($MD5_KEY,$DES_KEY, $this->getParam('resp'));
        $xml = simplexml_load_string($date); //创建 SimpleXML对象
        $data = json_decode(json_encode($xml),TRUE);
        $tradeNum = $data['TRADE']['ID'];
        if($data['RETURN']['CODE']==0000){
            ApiService::instance()->UpdateStatus($tradeNum);
            //ApiService::instance()->APPADDStatus($tradeNum);
            $response= "success";
        }
        else{
            ApiService::instance()->UpdateTradeNum($tradeNum);
           // $response= "success";
        }
        return $response;
    }

    public function SuccessUrl()
    {
        $tradeNum=$_GET['tradeNum'];

        //echo $tradeNum;
        // ApiService::instance()->UpdateStatus($tradeNum);
        $config = Config::get("jd_pay");
        // $serverPayUrl = $config["serverPayUrl"];
        return $this->view('webview.success_url');


    }
    public function FailUrl()
    {
        // $config = Config::get("jd_pay");
        // $serverPayUrl = $config["serverPayUrl"];
        return $this->view('webview.fail_url');


    }









}
